package com.netintech.project.system.ffmpeg;

import java.io.File;

/**
 * @author luda
 * @date 2021/3/24 15:20
 */
public class bbb {
    public void changeAmrToMp3(String sourcePath, String targetPath) throws Exception {

        String webroot = "D:\\ffmpeg\\ffmpeg-20191215-9fe0790-win64-static\\bin";

        Runtime run = null;

        try {

            run = Runtime.getRuntime();

            long start = System.currentTimeMillis();

            System.out.println(new File(webroot).getAbsolutePath());

            Process p = run.exec(
                    new File(webroot).getAbsolutePath() +
                            "\\ffmpeg.exe  -i " + "rtsp://admin:ks123456@172.16.11.172:554/h264/ch1/main/av_stream" +
                            " D:\\aaa111.mp4");


//            run.exit(0);


//            Thread.sleep(600000);

            //释放进程
//            p.getOutputStream().close();
//
//            p.getInputStream().close();
//
//            p.getErrorStream().close();

//            p.waitFor();


//            if (p.isAlive()) {
//                p.destroy();
//            }


            long end = System.currentTimeMillis();

            System.out.println(sourcePath + " convert success, costs:" + (end - start) + "ms");

        } catch (Exception e) {

            e.printStackTrace();

        } finally {

            //run调用lame解码器最后释放内存

//            run.freeMemory();

        }

    }

}
